<?php
//--------- Alimama Client
class Alimama_API_Client {
	var $debug_mode = false;
	var $params;
	var $http;
	var $api_address;
	var $version = "1.026b";
	var $success = false;
	var $result;
	var $error;
	var $last_query_api;
	var $autoparse = true;
	
	var $member_id;
	var $security_code;
	var $site_id;
	var $member_name;
	var $member_password;
	
	
	function Alimama_API_Client($debug_mode = false) {
		$this->reset_params();
		if (file_exists(ABSPATH.WPINC.'/class-snoopy.php')) {
			require_once(ABSPATH.WPINC.'/class-snoopy.php');
		} else {
			require_once(dirname(__FILE__) ."/class-snoopy.php");
		}
		$this->http = new Snoopy;
		$this->http->agent = 'Alimama Deluxe - http://www.wordpresscn.com';
		$this->http->rawheaders = array(
			'X-Alimama-API-Client' => 'Alimama Deluxe',
			'X-Alimama-API-Client-Version' => $this->version,
			'X-Alimama-API-Client-URL' => 'http://alimama-deluxe.wordpresscn.com/'
		);
		require_once(dirname(__FILE__) . "/xml.php");
		require_once(dirname(__FILE__) . "/portable-pear-json.php");
		$this->debug_mode = $debug_mode;
	}
	function init_member($member_id,$securitycode,$siteid=NULL) {
		if (!is_null($member_id)) {
			$this->member_id = $member_id;
			$this->security_code = $securitycode;
		}
		if (!is_null($siteid)) $this->site_id = $siteid;
	}
	function register($logname,$password,$nickname,$mobile) {
		$this->reset_params();
		$this->add_param('service','member_register');
		$this->add_param('logname',$logname);
		$this->add_param('passwd',md5($password));
		$this->add_param('nickname',$nickname);
		$this->add_param('mobile',$mobile);
		$this->add_param('logid',$logname);
		$this->last_query_api = 'register';
		return $this->request_alimama();
	}
	function site_add($name,$url,$type,$description,$sex,$age,$income,$job,$hobby=NULL) {
		if (empty($this->member_id) || empty($this->security_code)) {
			return false;
		}
		$this->reset_params();
		$this->add_param('service','site_add');
		$this->add_param('memberid',$this->member_id);
		$this->add_param('name',$name);
		$this->add_param('url',$url);
		$this->add_param('type',$type);
		$this->add_param('description',$description);
		$this->add_param('sex',$sex);
		$this->add_param('age',$age);
		$this->add_param('income',$income);
		$this->add_param('job',$job);
		if (!is_null($hobby)) $this->add_param('hobby',$hobby);	//not very clear in the API document, so we pass a blank value
		$this->last_query_api = 'site_add';
		return $this->request_alimama();
	}
	function site_edit($name=NULL,$description=NULL,$sex=NULL,$age=NULL,$income=NULL,$job=NULL,$hobby=NULL) {
		if (empty($this->member_id) || empty($this->security_code)) {
			return false;
		}
		if (is_null($this->site_id)) {
			return false;
		}
		$siteid = $this->site_id;
		$this->site_info();
		if ($this->success) {
			//nothing
		} else return false;
		$this->add_param('service','site_edit');
		$this->add_param('memberid',$this->member_id);
		$this->add_param('siteid',$siteid);
		if (!is_null($name)) $this->add_param('name',$name);
			else $this->add_param('name',$this->result['name']);
		if (!is_null($description)) $this->add_param('description',$description);
			else $this->add_param('description',$this->result['description']);
		if (!is_null($sex)) $this->add_param('sex',$sex);
			else $this->add_param('sex',$this->result['sex'][0]);
		if (!is_null($age)) $this->add_param('age',$age);
			else $this->add_param('age',$this->result['age'][0]);
		if (!is_null($income)) $this->add_param('income',$income);
			else $this->add_param('income',$this->result['income'][0]);
		if (!is_null($job)) $this->add_param('job',$job);
			else $this->add_param('job',$this->result['job'][0]);
		if (!is_null($hobby)) $this->add_param('hobby',$hobby);	//not very clear in the API document, so we pass a blank value
		$this->last_query_api = 'site_edit';
		return $this->request_alimama();
		
		
	}
	function zone_add($name,$transtype,$weekprice,$format,$sizecode,$needauditing,$homepage,$adzonecatids,$keywords,$zonedesc) {
		if (empty($this->member_id) || empty($this->security_code)) {
			return false;
		}
		$this->reset_params();
		$this->add_param('service','zone_add');
		$this->add_param('memberid',$this->member_id);
		$this->add_param('siteid',$this->site_id);
		$this->add_param('name',$name);
		$this->add_param('transtype',$transtype);
		$this->add_param('weekprice',$weekprice);
		$this->add_param('format',$format);
		$this->add_param('sizecode',$sizecode);
		$this->add_param('needauditing',$needauditing);
		$this->add_param('homepage',$homepage);
		$this->add_param('adzonecatids',$adzonecatids);
		if (!empty($keywords)) $this->add_param('keywords',$keywords);
		$this->add_param('zonedesc',$zonedesc);
//var_dump($this->params);die;
		$this->last_query_api = 'zone_add';
		return $this->request_alimama();
	}
	
	function zone_edit($adzoneid,$name = NULL,$weekprice = NULL,$format = NULL,$homepage = NULL, $needauditing = NULL,$keywords = NULL,$zonedesc = NULL) {
		if (empty($this->member_id) || empty($this->security_code) || empty($this->site_id)) {
			return false;
		}
		$this->reset_params();
		$this->add_param('service','zone_edit');
		$this->add_param('memberid',$this->member_id);
		$this->add_param('siteid',$this->site_id);
		$this->add_param('adzoneid',$adzoneid);
		if (!is_null($name)) $this->add_param('name',$name);
		if (!is_null($weekprice)) $this->add_param('weekprice',$weekprice);
		if (!is_null($format)) $this->add_param('format',$format);
		if (!is_null($needauditing)) $this->add_param('needauditing',$needauditing);
		if (!is_null($homepage)) $this->add_param('homepage',$homepage);
		if (!is_null($keywords)) $this->add_param('keywords',$keywords);
		if (!is_null($zonedesc)) $this->add_param('zonedesc',$zonedesc);
		
		if (is_null($name) && is_null($weekprice) && is_null($format) && is_null($needauditing) && is_null($homepage) && is_null($keywords) && is_null($zonedesc)) {
			return true;
		}
		$this->last_query_api = 'zone_edit';
		return $this->request_alimama();
	}
	function site_info($listsites = false) {
		if (empty($this->member_id) || empty($this->security_code)) {
			return false;
		}
		$this->reset_params();
		$this->add_param('service','site_info');
		$this->add_param('memberid',$this->member_id);
		if (!$listsites && !empty($this->site_id)) $this->add_param('siteid',$this->site_id);
		$this->last_query_api = 'site_info';
		return $this->request_alimama();
	}
	function zone_info($adzoneid = NULL) {
		if (empty($this->member_id) || empty($this->security_code)) {
			return false;
		}
		$this->reset_params();
		$this->add_param('service','zone_info');
		$this->add_param('memberid',$this->member_id);
		if (!is_null($adzoneid)) $this->add_param('adzoneid',$adzoneid);
		$this->last_query_api = 'zone_info';
		return $this->request_alimama();
	}
	//=====================================
	
	function add_param($name,$value) {
		if (empty($name)) return false;		//name should not be blank
		//if (empty($value)) return $this->remove_param($name);	//if value is blank, it means to delete this param
		$this->params[$name] = $value;
		return true;
	}
	function remove_param($name) {
		if (array_key_exists($name,$this->params)) {
			unset($this->params[$name]);
			return true;
		} else return false;
	}
	function reset_params() {
		$this->params = array();
	}
	function request_alimama() {
		if (empty($this->params['service'])) return false;
		if ($this->params['service'] != 'member_register') {
			if (empty($this->member_id) || empty($this->security_code)) return false;
		}
		//sort all parameters
		$params = $this->params;
		//first of all, we should convert all utf-8 code to GBK
		if (!function_exists('mb_convert_encoding') && !function_exists('iconv')) {
			require_once(dirname(__FILE__) . "/class.Chinese.php");
		}
		foreach(array_keys($params) as $key) {
			if (function_exists('mb_convert_encoding')) {
				$params[$key] = mb_convert_encoding($params[$key],'GBK','UTF-8');
			} elseif (function_exists('iconv')) {
				$params[$key] = iconv('UTF-8','GBK',$params[$key]);
			} else {
				$c = new Chinese("UTF8","GB2312",trim($params[$key]));
				$params[$key] = $c->ConvertIT();
			}
		}
		ksort($params);
		//generate the auth code
		if ($params['service'] != 'member_register') {
			reset($params);
			$n = "";
			while(list($key,$val) = each($params)) {
					//$n .= urlencode($key)."=".urlencode($val)."&";
					$n .= $key."=".$val."&";
			}
			if (substr($n,-1,1) == "&") $n = substr($n,0,-1);
			$n.= $this->security_code;
			//die($n);
			$params['sign'] = md5($n);
			$params['sign_type'] = 'MD5';
			//$params['pre_sign'] = $n;
		}
		//request alimama
		$this->result = false;
		$this->_set_api_address();
		//var_dump($params);
		$this->http->submit($this->api_address,$params);
		if (strpos($this->http->response_code,'200')!==false) {
			if (function_exists('mb_convert_encoding')) {
				$rr = mb_convert_encoding($this->http->results,'UTF-8','GBK');
			} elseif (function_exists('iconv')) {
				$rr = iconv('GBK','UTF-8',$this->http->results);
			} else {
				$c = new Chinese("GB2312","UTF8",trim($this->http->results));
				$rr = $c->ConvertIT();
			}
			$rr = str_replace('xml version="1.0" encoding="gbk"','xml version="1.0" encoding="UTF-8"',$rr);
			
			$this->result = XML_unserialize($rr);
			if ($this->autoparse) $this->parse_result();
			if (!empty($this->result)) return true;
		} else {
			//var_dump($params);
			//var_dump($this->http->response_code);
			return false;
		}
		
	}
	function parse_result($method=NULL) {
		if (empty($this->result)) {
			$this->success = false;
			return false;
		}
		$this->success = true;
		$r = &$this->result['response'];
		if ($r['is_success'] == 'false') {
			$this->success = false;
			$this->std_error($this->result);
			$this->result = false;
		} else {
			if (is_null($method)) $method = $this->last_query_api;
			if (empty($method)) return false;
			$this->success = true;
			switch($method) {
				case 'register':
					$reg = &$this->result['response']['data']['list']['member'];
					$this->result = array(
						'memberid'	=>	$reg['memberid'],
						'securityCode' => $reg['publickey']
					);
					break;
				case 'site_add':
					$this->result = array(
						'siteid'	=>	$this->result['response']['data']['list']['site']['siteid']
						);
					break;
				case 'site_edit':
					$this->result = array(
						'success'	=> true
					);
					break;
				case 'site_info':
					$r = &$this->result['response']['data']['list']['site'];
					if (intval($this->result['response']['data']['list attr']['size'])>1) {
						foreach ($r as $key=>$v) {
							$this->_json_parse_site_properties($r[$key]);
						}
						$this->result = $r;
					} else {
						$this->_json_parse_site_properties($r);
						$this->result = $r;
					}
					break;
				case 'zone_add':
					$r = &$this->result['response']['data']['list']['adzone']['adzoneid'];
					$this->result = array(
						'adzoneid' => $r
						);
					break;
				case 'zone_edit':
					$this->result = array(
						'success'	=> true
						);
					break;
				case 'zone_info':
					$r = &$this->result['response']['data']['list']['zone'];
					$this->result = $r;
					break;
			}
		}
	}
	function std_error($error) {
		$this->error = array(
			'code' => $error['response']['error_code'],
			'desc' => $error['response']['error_desc']
		);
	}
	function _json_parse_site_properties(&$siteinfo) {
		$j = new Services_JSON;
		$r = $j->decode($siteinfo['properties']);
		unset($siteinfo['properties']);
		$siteinfo['sex'] = $r->sex;
		$siteinfo['income'] = $r->income;
		$siteinfo['age'] = $r->age;
		$siteinfo['job'] = $r->job;
		
	}
	
	function _set_api_address() {
		if ($this->debug_mode) {
			$this->api_address = "http://www.alimama.org/individual/gateway.do";
		} else {
			$this->api_address = "http://www.alimama.com/individual/gateway.do";
		}
	}
	
	//===========================================
	
	function _alimama_url() {
		if ($this->debug_mode) {
			return "http://www.alimama.org";
		} else {
			return "http://www.alimama.com";
		}
	}
	function _http_get($url,$params=NULL) {
		if (is_null($params)) {
			$this->http->fetch($url);
		} else {
			//todo
			$this->http->submit($url,$params);
		}
		if (strpos($this->http->response_code,'200')!==false) {
			if (function_exists('mb_convert_encoding')) {
				$rr = mb_convert_encoding($this->http->results,'UTF-8','GBK');
			} elseif (function_exists('iconv')) {
				$rr = iconv('GBK','UTF-8',$this->http->results);
			} else {
				$c = new Chinese("GB2312","UTF8",trim($this->http->results));
				$rr = $c->ConvertIT();
			}
			//$rr = str_replace('xml version="1.0" encoding="gbk"','xml version="1.0" encoding="UTF-8"',$rr);
			return $rr;
		} else {
			return false;
		}
	}
	function _http_login_alimama() {
		if (empty($this->member_name) || empty($this->member_password)) return false;
		$url = $this->_alimama_url();
		$url .= "/membersvc/member/login.htm";
		$params = array("action"=>"MembersAction",
						"forward"=>"",
						"_fmm.l._0.l"=>"$this->member_name",
						"_fmm.l._0.lo"=>md5($this->member_password),
						"originalLogpasswd"=>"$this->member_password",
						"event_submit_do_login"=>"18");
		$r = $this->_http_get($url,$params);
		if ($r) {
			if (strpos($r,'您输入的用户名或密码错误！')!==false) {
				return false;
			} elseif (strpos($r,'账户还未激活')!==false) {
				return false;
			} else {
				return true;
			}
		} else {
			return false;
		}
	}
	function get_seller_adzones_detail() {
		if (!$this->_http_login_alimama()) return false;
		$url = $this->_alimama_url();
		$url .= "/membersvc/report/seller_adzones_detail.htm";
		$dt = getdate();
		$today = $this->_yday_to_ymd($dt['year'],$dt['yday']+1);
		$fromday = $this->_yday_to_ymd($dt['year'],$dt['yday']-29);
		$params = array("toPage"=>"1",
						"perPageSize"=>"3000",
						"adzone"=>"0",
						"begintime"=>$fromday,
						"endtime"=>$today);
		$r = $this->_http_get($url,$params);
		if (preg_match("/访问人数.+?<\/tr>(.*)<tr.+?>总和<\/td>/is",$r,$m)) {
			if (preg_match_all("/<tr>(.+?)<\/tr>/is",$m[1],$ms)!== false) {
				if (is_array($ms[1]) && count($ms[1])) {
					$sellerdata = array();
					foreach ($ms[1] as $item) {
						if (preg_match_all("/<td.*?>(.*?)(&nbsp;)*<\/td>/i",$item,$mvs)!==false) {
							$ii = array("date"=>trim($mvs[1][0]),"brow"=>intval(trim($mvs[1][2])),"visit"=>intval(trim($mvs[1][3])));
							$ii_name = trim($mvs[1][1]);
							$sellerdata[$ii_name]['data'][] = $ii;
						}
					}
				}
				return $sellerdata;
			}
			return false;
		}else {
			return false;
		}
	}
	function _yday_to_ymd($year,$yday) {
		$year = intval($year);$yday = intval($yday);
		if ($yday < 0) $year--;
		$rn = false;
		if ($year % 100 == 0) $rn = ($year % 400 == 0);
		else $rn = ($year % 4 == 0);
		
		$m = array(31,28,31,30,31,30,31,31,30,31,30,31);
		if ($rn) $m[1] = 29;

		if ($yday < 0) $yday += array_sum($m);

		for($i=0;$i<12;$i++) {
			if ($i == 0) $before = 0;
			else $before = array_sum(array_slice($m,0,$i));
			$after = array_sum(array_slice($m,0,$i+1));
			if ($yday > $before && $yday <= $after) {
				$month = $i+1;
				$mday = $yday - $before;
				break;
			}
		}
		
		return sprintf("%d-%02d-%02d",$year,$month,$mday);
	}
} // end of class

class alimama_adzone_types {
	var $format;
	var $transtype;
	var $sizecode;
	var $status;
	var $needauditing;
	var $homepage;
	var $adzonecatcats;
	var $adzonecatids;
	
	function alimama_adzone_types() {
		$o = &$this->format;
		$o = array();
		$o[1] = '文字';
		$o[2] = '图片';
		$o[3] = '文字或图片';
		
		$o = &$this->transtype;
		$o[1] = '按点击付费(CPC)';
		$o[2] = '按时长付费(CPT)';
		$o[3] = '按点击和时长付费(CPT+CPC)';
		$o[4] = '按展示付费(CPM)';
		
		$o = &$this->sizecode;
		$o['11'] = '横幅广告 760x90';
		$o['12'] = '横幅广告 468x60';
		$o['13'] = '横幅广告 250x60';
		$o['14'] = '横幅广告 728x90';
		$o['15'] = '横幅广告 950x90';
		$o['21'] = '垂直广告 120x600';
		$o['22'] = '垂直广告 120x240';
		$o['23'] = '垂直广告 160x600';
		$o['31'] = '巨幅广告 180x250';
		$o['32'] = '巨幅广告 250x300';
		$o['33'] = '巨幅广告 360x190';
		$o['34'] = '巨幅广告 250x250';
		$o['35'] = '巨幅广告 200x200';
		$o['36'] = '巨幅广告 336x280';
		$o['37'] = '巨幅广告 300x250';
		$o['41'] = '小幅广告 120x60';
		
		$o = &$this->status;
		$o['N'] = '未激活';
		$o['A'] = '上架';
		$o['O'] = '下架';
		$o['R'] = '审核拒绝';
		$o['D'] = '删除';
		
		$o = &$this->needauditing;
		$o[1] = '需要审核';
		$o[0] = '不需要审核';
		
		$o = &$this->homepage;
		$o[0] = '不在首页';
		$o[1] = '在首页';
		
		
		$o = &$this->adzonecatids;
		$o['137101']=array('name'=>"美容健身",'sub'=>array('10101'=>"美体健身",'10102'=>"美容美发",'10199'=>"综合/其它"));
		$o['138102']=array('name'=>"互联网应用",'sub'=>array('10201'=>"个人空间",'10202'=>"网站建设",'10203'=>"网络工具",'10299'=>"综合/其它"));
		$o['139103']=array('name'=>"数码硬件",'sub'=>array('10301'=>"mp3/mp4",'10302'=>"游戏机",'10303'=>"数码相机/摄像机",'10304'=>"数码配件",'10305'=>"Apple",'10306'=>"计算机",'10307'=>"数码周边",'10399'=>"综合/其它"));
		$o['140104']=array('name'=>"科技资讯",'sub'=>array('10401'=>"IT资讯",'10402'=>"技术开发",'10403'=>"数据库与系统管理",'10404'=>"互联网与电信",'10499'=>"综合/其它"));
		$o['141105']=array('name'=>"软件应用下载",'sub'=>array('10501'=>"应用下载",'10502'=>"素材下载",'10599'=>"综合/其它"));
		$o['142106']=array('name'=>"美图欣赏",'sub'=>array('10601'=>"屏保/壁纸 ",'10602'=>"图片",'10699'=>"综合/其它"));
		$o['143107']=array('name'=>"人文艺术",'sub'=>array('10701'=>"爱好",'10702'=>"摄影艺术",'10703'=>"艺术欣赏",'10704'=>"人文荟萃",'10705'=>"军事国防",'10706'=>"收藏投资 ",'10799'=>"综合/其它"));
		$o['144108']=array('name'=>"生活资讯",'sub'=>array('10801'=>"餐饮",'10802'=>"家居园艺",'10803'=>"娱乐场所",'10804'=>"星座",'10805'=> "家用电器",'10806'=>"美食烹饪",'10807'=>"家具装修",'10808'=>"住宿出行 ",'10899'=>"综合/其它"));
		$o['145109']=array('name'=>"体育竞技",'sub'=>array('10999'=>"综合/其它"));
		$o['146110']=array('name'=>"彩票博彩",'sub'=>array('11099'=>"综合/其它"));
		$o['147111']=array('name'=>"宠物",'sub'=>array('11199'=>"综合/其它"));
		$o['148112']=array('name'=>"动漫卡通",'sub'=>array('11299'=>"综合/其它"));
		$o['149113']=array('name'=>"游戏",'sub'=>array('11301'=>"网络游戏",'11302'=>"PC游戏",'11303'=>"竞技游戏",'11399'=>"综合/其它"));
		$o['150114']=array('name'=>"书刊",'sub'=>array('11401'=>"书刊在线",'11402'=>"书刊下载",'11499'=>"综合/其它"));
		$o['151115']=array('name'=>"影音娱乐",'sub'=>array('11501'=>"影音下载",'11502'=>"明星轶事",'11503'=>"影视资讯",'11599'=>"综合/其它"));
		$o['152116']=array('name'=>"手机/手机应用",'sub'=>array('11601'=>"手机和手机配件",'11602'=>"手机相关下载",'11699'=>"综合/其它"));
		$o['153117']=array('name'=>"教育培训",'sub'=>array('11701'=>"外语培训",'11702'=>"特长培训",'11703'=>"留学移民",'11704'=>"考研", '11705'=>"职业认证培训",'11706'=>"计算机认证培训",'11707'=>"驾校",'11708'=>"大专院校研究所",'11709'=>"继续教育学院 ",'11799'=>"综合/其它"));
		$o['154118']=array('name'=>"汽车",'sub'=>array('11801'=>"汽车资讯",'11802'=>"维修保养",'11803'=>"汽车租赁购买",'11804'=>"汽车维修",'11899'=>"综合/其它"));
		$o['155119']=array('name'=>"投资理财",'sub'=>array('11901'=>"经济金融资讯",'11902'=>"证券投资",'11903'=>"家庭理财",'11999'=>"综合/其它"));
		$o['156120']=array('name'=>"房地产",'sub'=>array('12001'=>"房屋买卖",'12002'=>"楼市行情",'12003'=>"房屋租赁",'12004'=>"买卖服务与中介",'12099'=>"综合/其它"));
		$o['157121']=array('name'=>"招聘",'sub'=>array('12199'=>"综合/其它"));
		$o['158122']=array('name'=>"行业网站",'sub'=>array('12201'=>"工业品",'12202'=>"商业品",'12203'=>"商业服务",'12204'=>"原材料",'12299'=>"综合/其它"));
		$o['159123']=array('name'=>"科学研究",'sub'=>array('12301'=>"资料参考下载",'12302'=>"人文科学研究",'12303'=>"自然科学研究",'12399'=>"综合/其它"));
		$o['160124']=array('name'=>"服装饰品",'sub'=>array('12401'=>"鞋包",'12402'=>"服装",'12403'=>"饰品",'12499'=>"综合/其它"));
		$o['161125']=array('name'=>"门户网站",'sub'=>array('12501'=>"地方性门户",'12502'=>"综合新闻站",'12503'=>"非主流艺术",'12599'=>"综合/其它"));
		$o['162126']=array('name'=>"两性生活",'sub'=>array('12601'=>"生殖健康",'12602'=>"性教育",'12699'=>"综合/其它"));
		$o['163127']=array('name'=>"医疗保健",'sub'=>array('12701'=>"疾病治疗",'12702'=>"营养保健",'12703'=>"医疗设备",'12704'=>"母婴频道",'12799'=>"综合/其它"));
		$o['164128']=array('name'=>"留学移民",'sub'=>array('12801'=>"移民信息",'12802'=>"出国签证",'12803'=>"留学信息",'12804'=>"留学考试 ",'12805'=>"留学移民服务",'12899'=>"综合/其它"));
		$o['165129']=array('name'=>"戶外旅游 ",'sub'=>array('12901'=>"自助游",'12902'=>"户外活动",'12903'=>"旅行社",'12999'=>"综合/其它"));
		$o['166130']=array('name'=>"网址导航",'sub'=>array('13099'=>"综合/其它"));
		$o['167131']=array('name'=>"网络社区",'sub'=>array('13101'=>"同学同乡圈",'13102'=>"交友联谊",'13103'=>"兴趣圈",'13104'=>"同志社区",'13199'=>"综合/其它"));
		$o['168132']=array('name'=>"个人博客",'sub'=>array('13201'=>"娱乐",'13202'=>"体育",'13203'=>"女性",'13204'=>"教育",'13205'=>"科技",'13206'=>"文化",'13207'=>"财经",'13208'=>"社会",'13299'=>"综合/其它"));
		$o['169133']=array('name'=>"其它",'sub'=>array('13399'=>"综合/其它"));
/*		$o['1001'] = '爱好收藏';
		$o['1002'] = '宠物花鸟';
		$o['1003'] = '餐饮美食';
		$o['1004'] = '美容减肥';
		$o['1005'] = '体育健身';
		$o['1006'] = '彩票博彩';
		$o['1007'] = '交友聊天';
		$o['1008'] = '电影、音乐';
		$o['1009'] = '动漫游戏';
		$o['1010'] = '文学、艺术';
		$o['1011'] = '美术摄像（影）';
		$o['1013'] = '旅游户外';
		$o['1014'] = '教育培训';
		$o['1015'] = '人才招聘';
		$o['1016'] = '汽车';
		$o['1017'] = '金融';
		$o['1018'] = '医疗保健';
		$o['1019'] = '房地产';
		$o['1020'] = '地方性门户';
		$o['1022'] = '服装饰品';
		$o['1023'] = '手机、数码产品';
		$o['1024'] = '电脑软件、硬件';
		$o['1028'] = '行业网站';
		$o['1033'] = '政府和机构组织';
		$o['1034'] = '军事';
		$o['1035'] = '娱乐视频';
		$o['1036'] = '地图服务';
		$o['1037'] = '手机网络';
		$o['1038'] = '下载类';
		$o['1039'] = '家居、生活';
		$o['1099'] = '其它';
*/
		}
		function adzoneid2catdesc($id) {
			$o = &$this->adzonecatids;
			$rtn = '';
			foreach ($o as $a) {
				foreach ($a['sub'] as $key=>$value) {
					if ($key == $id) {
						$rtn = sprintf("%s => %s",$a['name'],$value);
						break;
					}
				}
			}
			if (empty($rtn)) return '未找到分类';
			else return $rtn;
		}
}
?>